﻿using System;
using System.Configuration;
using Comsenz.Base.Configs;

namespace Comsenz.UCenter.Configs
{
    /// <summary>
    /// Discuz配置
    /// </summary>
    /// <author>Chiron</author>
    public class UCenterConfig : ConfigurationSection
    {
        private UCenterConfig() { }
        /// <summary>
        /// Discuz配置实例
        /// </summary>
        public readonly static UCenterConfig Instance;
        /// <summary>
        /// 初始化Discuz配置
        /// </summary>
        static UCenterConfig()
        {
            try
            {
                Instance = ConfigurationManager.GetSection("comsenz.ucenter") as UCenterConfig;
            }
            catch (Exception ex)
            {
#if DEBUG
                throw ex;
#endif
            }

            if (Instance == null) throw new Exception("无法初始化 Comsenz UCenter 配置,请检查是否已正确配置了配置文件.");
        }

        #region 非配置属性
        /// <summary>
        /// 当前使用的链接配置
        /// </summary>
        public ConnectConfig CurrentConnectConfig
        {
            get
            {
                var connect = Connects[ConnectName] ?? Connects[0];
                return connect;
            }
        }
        #endregion 非配置属性

        #region 配置属性
        /// <summary>
        /// 启用状态
        /// </summary>
        [ConfigurationProperty("enabled", IsRequired = false, DefaultValue = false)]
        public bool Enabled
        {
            get
            {
                return (bool)this["enabled"];
            }
            set
            {
                this["enabled"] = value;
            }
        }
        /// <summary>
        /// 要使用的链接方式名
        /// </summary>
        [ConfigurationProperty("connectName", IsRequired = true)]
        public string ConnectName
        {
            get
            {
                return this["connectName"] as string;
            }
            set
            {
                this["connectName"] = value;
            }
        }

        /// <summary>
        /// 链接方式配置
        /// </summary>
        [ConfigurationProperty("connects", IsRequired = true)]
        public ConnectCollection Connects
        {
            get
            {
                return this["connects"] as ConnectCollection;
            }
        }

        #region ClientAPI Configs

        /// <summary>
        /// 删除用户
        /// </summary>
        [ConfigurationProperty("deleteUser", DefaultValue = true)]
        public bool DeleteUser
        {
            get
            {
                return (bool)this["deleteUser"];
            }
        }

        /// <summary>
        /// 用户改名
        /// </summary>
        [ConfigurationProperty("renameUser", DefaultValue = true)]
        public bool RenameUser
        {
            get
            {
                return (bool)this["renameUser"];
            }
        }

        /// <summary>
        /// 获取标签
        /// </summary>
        [ConfigurationProperty("getTag", DefaultValue = true)]
        public bool GetTag
        {
            get
            {
                return (bool)this["getTag"];
            }
        }

        /// <summary>
        /// 同步登录
        /// </summary>
        [ConfigurationProperty("synlogin", DefaultValue = true)]
        public bool Synlogin
        {
            get
            {
                return (bool)this["synlogin"];
            }
        }

        /// <summary>
        /// 同步注销
        /// </summary>
        [ConfigurationProperty("synlogout", DefaultValue = true)]
        public bool Synlogout
        {
            get
            {
                return (bool)this["synlogout"];
            }
        }

        /// <summary>
        /// 更改用户密码
        /// </summary>
        [ConfigurationProperty("updatePassword", DefaultValue = true)]
        public bool UpdatePassword
        {
            get
            {
                return (bool)this["updatePassword"];
            }
        }

        /// <summary>
        /// 更新关键字列表
        /// </summary>
        [ConfigurationProperty("updatebadWords", DefaultValue = true)]
        public bool UpdatebadWords
        {
            get
            {
                return (bool)this["updatebadWords"];
            }
        }

        /// <summary>
        /// 更新域名解析缓存
        /// </summary>
        [ConfigurationProperty("updateHosts", DefaultValue = true)]
        public bool UpdateHosts
        {
            get
            {
                return (bool)this["updateHosts"];
            }
        }

        /// <summary>
        /// 更新应用列表
        /// </summary>
        [ConfigurationProperty("updateApps", DefaultValue = true)]
        public bool UpdateApps
        {
            get
            {
                return (bool)this["updateApps"];
            }
        }

        /// <summary>
        /// 更新客户端缓存
        /// </summary>
        [ConfigurationProperty("updateClient", DefaultValue = true)]
        public bool UpdateClient
        {
            get
            {
                return (bool)this["updateClient"];
            }
        }

        /// <summary>
        /// 更新用户积分
        /// </summary>
        [ConfigurationProperty("updateCredit", DefaultValue = true)]
        public bool UpdateCredit
        {
            get
            {
                return (bool)this["updateClient"];
            }
        }

        /// <summary>
        /// 向 UC 提供积分
        /// </summary>
        [ConfigurationProperty("getCredit", DefaultValue = true)]
        public bool GetCredit
        {
            get
            {
                return (bool)this["getCredit"];
            }
        }

        /// <summary>
        /// 向 UCenter 提供积分设置
        /// </summary>
        [ConfigurationProperty("getCreditSettings", DefaultValue = true)]
        public bool GetCreditSettings
        {
            get
            {
                return (bool)this["getCreditSettings"];
            }
        }

        /// <summary>
        /// 更新应用积分设置
        /// </summary>
        [ConfigurationProperty("updateCreditSettings", DefaultValue = true)]
        public bool UpdateCreditSettings
        {
            get
            {
                return (bool)this["updateCreditSettings"];
            }
        }

        /// <summary>
        /// 向 UCHome 添加feed
        /// </summary>
        [ConfigurationProperty("addFeed", DefaultValue = true)]
        public bool AddFeed
        {
            get
            {
                return (bool)this["addFeed"];
            }
        }

        #endregion ClientAPI Configs
        #endregion 配置属性
    }
}
